<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>设置下拉框中的默认随机选中项</title>
</head>
<body>
    <input type="button" value="选择" id="btn">
    <br>
    <select id="travel">
        <option>北京</option>
        <option>西藏</option>
        <option>丽江</option>
        <option>重庆</option>
        <option>杭州</option>
        <option>云南</option>
        <option>双月湾</option>
        <option>南澳岛</option>
        <option>迪士尼</option>
    </select>
    <script>
        // 1. 获取元素
       var btn = document.getElementById("btn"); 
       var travel = document.getElementById("travel"); 
       var opts = travel.children;

       // 2. 给按钮添加点击事件
       btn.onclick = function () {
        // 3. 随即选择一个 option
        var n = Math.floor(Math.random() * opts.length);
        // 设置对应的随机的属性
        opts[n].selected = true;
       };
    </script>
</body>
</html>